## This file makes the chord diagram for the voting example

load("vote/out/vote_out_pois.rda")

# Create aggregate rule set. See agg_BRS documentation from the BRS package
set.seed(123)
agg <- agg_BRS(fit=out, X=X, Y=Y, maxLen=3, split = F, simplify = T, 
               oppmat=oppmat, oppind=oppind, minProp = .05)


# Plot
png("figures/vote_agg_chord_together.png", width = 2, height = 2.25, units = 'in', res = 300)
featGroups <- rbind(featGroups[which(featGroups[, 1]=="polint"), ], featGroups[-which(featGroups[, 1]=="polint"), ])
featGroups[, 1] <- factor(featGroups[, 1], levels=featGroups[, 1])
featGroups[, 2] <- factor(featGroups[, 2], levels=featGroups[, 2])

# see helper.R for documentation on plot_chord function
plot_chord(agg, 
           featureGroups = featGroups,
           linkColors=c(RColorBrewer::brewer.pal(9, "Set3")[-2], RColorBrewer::brewer.pal(8, "Accent")),
           gridColors = "gray",
           textSize =1, side_mar=0, top_mar=0)
dev.off()
